<template>
    <div class="usersSetting">
        <div class="crumbs">
            <el-breadcrumb separator-class="el-icon-arrow-right">
                <el-breadcrumb-item>系统设置</el-breadcrumb-item>
                <el-breadcrumb-item>用户设置</el-breadcrumb-item>
            </el-breadcrumb>
        </div>
        <div class="container">
            <el-form :model="userForm" label-position="right">
                <el-row>
                    <el-col :span="12">
                        <el-form-item label="用户名" label-width="120px">
                            <el-input v-model="userForm.userName" autocomplete="off"></el-input>
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="密码" label-width="120px">
                            <el-input v-model="userForm.password" autocomplete="off"></el-input>
                        </el-form-item>
                    </el-col>
                </el-row>
            </el-form>
            <div slot="footer" style="text-align: center">
                <el-button @click="refresh">重 置</el-button>
                <el-button type="primary" @click="saveUserForm">保 存</el-button>
            </div>
        </div>
    </div>
</template>
<script>
import { UPDATE_HR } from '@/api/api.js'
export default {
    name: 'usersSetting',
    data() {
        return {
            userForm: {
                userName: '',
                password: ''
            }
        }
    },
    methods: {
        refresh() {
            this.userForm.userName = ''
            this.userForm.password = ''
        },
        async saveUserForm() {
            let that = this
            let formData = new FormData()
            formData.append('userName', this.userForm.userName)
            formData.append('password', this.userForm.password)
            await that.$POST(`${UPDATE_HR}`, formData)
            .then(res => {
                if(res.code == 200) {
                    that.$message.success(res.msg)
                    return this.$route.path.replace('/','');
                } else {
                    that.$message.error(res.msg)
                }
            })
        }
    },
}
</script>